
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>The staticfiles app &#8212; Django 1.11.22.dev20190603194737 documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="The syndication feed framework" href="syndication.html" />
    <link rel="prev" title="The “sites” framework" href="sites.html" />



 
<script type="text/javascript" src="../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 1.11.22.dev20190603194737 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="sites.html" title="The “sites” framework">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="syndication.html" title="The syndication feed framework">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-staticfiles">
            
  <div class="section" id="s-module-django.contrib.staticfiles">
<span id="s-the-staticfiles-app"></span><span id="module-django.contrib.staticfiles"></span><span id="the-staticfiles-app"></span><h1>The <code class="docutils literal notranslate"><span class="pre">staticfiles</span></code> app<a class="headerlink" href="#module-django.contrib.staticfiles" title="Permalink to this headline">¶</a></h1>
<p><code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles</span></code> collects static files from each of your
applications (and any other places you specify) into a single location that
can easily be served in production.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">For an introduction to the static files app and some usage examples, see
<a class="reference internal" href="../../howto/static-files/index.html"><span class="doc">Managing static files (e.g. images, JavaScript, CSS)</span></a>. For guidelines on deploying static files,
see <a class="reference internal" href="../../howto/static-files/deployment.html"><span class="doc">Deploying static files</span></a>.</p>
</div>
<div class="section" id="s-settings">
<span id="s-staticfiles-settings"></span><span id="settings"></span><span id="staticfiles-settings"></span><h2>Settings<a class="headerlink" href="#settings" title="Permalink to this headline">¶</a></h2>
<p>See <a class="reference internal" href="../settings.html#settings-staticfiles"><span class="std std-ref">staticfiles settings</span></a> for details on the
following settings:</p>
<ul class="simple">
<li><a class="reference internal" href="../settings.html#std:setting-STATIC_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code></a></li>
<li><a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a></li>
<li><a class="reference internal" href="../settings.html#std:setting-STATICFILES_DIRS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_DIRS</span></code></a></li>
<li><a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_STORAGE</span></code></a></li>
<li><a class="reference internal" href="../settings.html#std:setting-STATICFILES_FINDERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_FINDERS</span></code></a></li>
</ul>
</div>
<div class="section" id="s-management-commands">
<span id="management-commands"></span><h2>Management Commands<a class="headerlink" href="#management-commands" title="Permalink to this headline">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles</span></code> exposes three management commands.</p>
<div class="section" id="s-collectstatic">
<span id="collectstatic"></span><h3><code class="docutils literal notranslate"><span class="pre">collectstatic</span></code><a class="headerlink" href="#collectstatic" title="Permalink to this headline">¶</a></h3>
<dl class="django-admin">
<dt id="django-admin-collectstatic">
<code class="descname">django-admin collectstatic</code><a class="headerlink" href="#django-admin-collectstatic" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Collects the static files into <a class="reference internal" href="../settings.html#std:setting-STATIC_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code></a>.</p>
<p>Duplicate file names are by default resolved in a similar way to how template
resolution works: the file that is first found in one of the specified
locations will be used. If you’re confused, the <a class="reference internal" href="#django-admin-findstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">findstatic</span></code></a> command
can help show you which files are found.</p>
<p>On subsequent <code class="docutils literal notranslate"><span class="pre">collectstatic</span></code> runs (if <code class="docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code> isn’t empty), files
are copied only if they have a modified timestamp greater than the timestamp of
the file in <code class="docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code>. Therefore if you remove an application from
<a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a>, it’s a good idea to use the <a class="reference internal" href="#cmdoption-collectstatic-clear"><code class="xref std std-option docutils literal notranslate"><span class="pre">collectstatic</span>
<span class="pre">--clear</span></code></a> option in order to remove stale static files.</p>
<p>Files are searched by using the <a class="reference internal" href="../settings.html#std:setting-STATICFILES_FINDERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">enabled</span> <span class="pre">finders</span></code></a>. The default is to look in all locations defined in
<a class="reference internal" href="../settings.html#std:setting-STATICFILES_DIRS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_DIRS</span></code></a> and in the <code class="docutils literal notranslate"><span class="pre">'static'</span></code> directory of apps
specified by the <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a> setting.</p>
<p>The <a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> management command calls the
<a class="reference internal" href="#django.contrib.staticfiles.storage.StaticFilesStorage.post_process" title="django.contrib.staticfiles.storage.StaticFilesStorage.post_process"><code class="xref py py-meth docutils literal notranslate"><span class="pre">post_process()</span></code></a>
method of the <a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_STORAGE</span></code></a> after each run and passes
a list of paths that have been found by the management command. It also
receives all command line options of <a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a>. This is used
by the <a class="reference internal" href="#django.contrib.staticfiles.storage.CachedStaticFilesStorage" title="django.contrib.staticfiles.storage.CachedStaticFilesStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">CachedStaticFilesStorage</span></code></a>
by default.</p>
<p>By default, collected files receive permissions from
<a class="reference internal" href="../settings.html#std:setting-FILE_UPLOAD_PERMISSIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_PERMISSIONS</span></code></a> and collected directories receive permissions
from <a class="reference internal" href="../settings.html#std:setting-FILE_UPLOAD_DIRECTORY_PERMISSIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_DIRECTORY_PERMISSIONS</span></code></a>. If you would like different
permissions for these files and/or directories, you can subclass either of the
<a class="reference internal" href="#staticfiles-storages"><span class="std std-ref">static files storage classes</span></a> and specify the
<code class="docutils literal notranslate"><span class="pre">file_permissions_mode</span></code> and/or <code class="docutils literal notranslate"><span class="pre">directory_permissions_mode</span></code> parameters,
respectively. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.contrib.staticfiles</span> <span class="k">import</span> <span class="n">storage</span>

<span class="k">class</span> <span class="nc">MyStaticFilesStorage</span><span class="p">(</span><span class="n">storage</span><span class="o">.</span><span class="n">StaticFilesStorage</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;file_permissions_mode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mo">0o640</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;directory_permissions_mode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mo">0o760</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">MyStaticFilesStorage</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div>
</div>
<p>Then set the <a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_STORAGE</span></code></a> setting to
<code class="docutils literal notranslate"><span class="pre">'path.to.MyStaticFilesStorage'</span></code>.</p>
<p>Some commonly used options are:</p>
<dl class="django-admin-option">
<dt id="cmdoption-collectstatic-noinput">
<code class="descname">--noinput</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--no-input</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-collectstatic-noinput" title="Permalink to this definition">¶</a></dt>
<dd><p>Do NOT prompt the user for input of any kind.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="cmdoption-collectstatic-ignore">
<code class="descname">--ignore</code><code class="descclassname"> PATTERN</code><code class="descclassname">, </code><code class="descname">-i</code><code class="descclassname"> PATTERN</code><a class="headerlink" href="#cmdoption-collectstatic-ignore" title="Permalink to this definition">¶</a></dt>
<dd><p>Ignore files or directories matching this glob-style pattern. Use multiple
times to ignore more.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="cmdoption-collectstatic-dry-run">
<code class="descname">--dry-run</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">-n</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-collectstatic-dry-run" title="Permalink to this definition">¶</a></dt>
<dd><p>Do everything except modify the filesystem.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="cmdoption-collectstatic-clear">
<code class="descname">--clear</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">-c</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-collectstatic-clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Clear the existing files before trying to copy or link the original file.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="cmdoption-collectstatic-link">
<code class="descname">--link</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">-l</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-collectstatic-link" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a symbolic link to each file instead of copying.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="cmdoption-collectstatic-no-post-process">
<code class="descname">--no-post-process</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-collectstatic-no-post-process" title="Permalink to this definition">¶</a></dt>
<dd><p>Don’t call the
<a class="reference internal" href="#django.contrib.staticfiles.storage.StaticFilesStorage.post_process" title="django.contrib.staticfiles.storage.StaticFilesStorage.post_process"><code class="xref py py-meth docutils literal notranslate"><span class="pre">post_process()</span></code></a>
method of the configured <a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_STORAGE</span></code></a> storage backend.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="cmdoption-collectstatic-no-default-ignore">
<code class="descname">--no-default-ignore</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-collectstatic-no-default-ignore" title="Permalink to this definition">¶</a></dt>
<dd><p>Don’t ignore the common private glob-style patterns <code class="docutils literal notranslate"><span class="pre">'CVS'</span></code>, <code class="docutils literal notranslate"><span class="pre">'.*'</span></code>
and <code class="docutils literal notranslate"><span class="pre">'*~'</span></code>.</p>
</dd></dl>

<p>For a full list of options, refer to the commands own help by running:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> python manage.py collectstatic --help
</pre></div>
</div>
<div class="section" id="s-customizing-the-ignored-pattern-list">
<span id="s-customize-staticfiles-ignore-patterns"></span><span id="customizing-the-ignored-pattern-list"></span><span id="customize-staticfiles-ignore-patterns"></span><h4>Customizing the ignored pattern list<a class="headerlink" href="#customizing-the-ignored-pattern-list" title="Permalink to this headline">¶</a></h4>
<div class="versionadded">
<span class="title">New in Django 1.10.</span> </div>
<p>The default ignored pattern list, <code class="docutils literal notranslate"><span class="pre">['CVS',</span> <span class="pre">'.*',</span> <span class="pre">'*~']</span></code>, can be customized in
a more persistent way than providing the <code class="docutils literal notranslate"><span class="pre">--ignore</span></code> command option at each
<code class="docutils literal notranslate"><span class="pre">collectstatic</span></code> invocation. Provide a custom <a class="reference internal" href="../applications.html#django.apps.AppConfig" title="django.apps.AppConfig"><code class="xref py py-class docutils literal notranslate"><span class="pre">AppConfig</span></code></a>
class, override the <code class="docutils literal notranslate"><span class="pre">ignore_patterns</span></code> attribute of this class and replace
<code class="docutils literal notranslate"><span class="pre">'django.contrib.staticfiles'</span></code> with that class path in your
<a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a> setting:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.contrib.staticfiles.apps</span> <span class="kn">import</span> <span class="n">StaticFilesConfig</span>

<span class="k">class</span> <span class="nc">MyStaticFilesConfig</span><span class="p">(</span><span class="n">StaticFilesConfig</span><span class="p">):</span>
    <span class="n">ignore_patterns</span> <span class="o">=</span> <span class="p">[</span><span class="o">...</span><span class="p">]</span>  <span class="c1"># your custom ignore list</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-findstatic">
<span id="findstatic"></span><h3><code class="docutils literal notranslate"><span class="pre">findstatic</span></code><a class="headerlink" href="#findstatic" title="Permalink to this headline">¶</a></h3>
<dl class="django-admin">
<dt id="django-admin-findstatic">
<code class="descname">django-admin findstatic staticfile [staticfile ...]</code><a class="headerlink" href="#django-admin-findstatic" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Searches for one or more relative paths with the enabled finders.</p>
<p>For example:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> python manage.py findstatic css/base.css admin/js/core.js
<span class="go">Found &#39;css/base.css&#39; here:</span>
<span class="go">  /home/special.polls.com/core/static/css/base.css</span>
<span class="go">  /home/polls.com/core/static/css/base.css</span>
<span class="go">Found &#39;admin/js/core.js&#39; here:</span>
<span class="go">  /home/polls.com/src/django/contrib/admin/media/js/core.js</span>
</pre></div>
</div>
<dl class="django-admin-option">
<dt id="cmdoption-findstatic-arg-findstatic">
<code class="descname">findstatic</code><code class="descclassname"> --first</code><a class="headerlink" href="#cmdoption-findstatic-arg-findstatic" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>By default, all matching locations are found. To only return the first match
for each relative path, use the <code class="docutils literal notranslate"><span class="pre">--first</span></code> option:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> python manage.py findstatic css/base.css --first
<span class="go">Found &#39;css/base.css&#39; here:</span>
<span class="go">  /home/special.polls.com/core/static/css/base.css</span>
</pre></div>
</div>
<p>This is a debugging aid; it’ll show you exactly which static file will be
collected for a given path.</p>
<p>By setting the <code class="docutils literal notranslate"><span class="pre">--verbosity</span></code> flag to 0, you can suppress the extra output and
just get the path names:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> python manage.py findstatic css/base.css --verbosity <span class="m">0</span>
<span class="go">/home/special.polls.com/core/static/css/base.css</span>
<span class="go">/home/polls.com/core/static/css/base.css</span>
</pre></div>
</div>
<p>On the other hand, by setting the <code class="docutils literal notranslate"><span class="pre">--verbosity</span></code> flag to 2, you can get all
the directories which were searched:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> python manage.py findstatic css/base.css --verbosity <span class="m">2</span>
<span class="go">Found &#39;css/base.css&#39; here:</span>
<span class="go">  /home/special.polls.com/core/static/css/base.css</span>
<span class="go">  /home/polls.com/core/static/css/base.css</span>
<span class="go">Looking in the following locations:</span>
<span class="go">  /home/special.polls.com/core/static</span>
<span class="go">  /home/polls.com/core/static</span>
<span class="go">  /some/other/path/static</span>
</pre></div>
</div>
</div>
<div class="section" id="s-runserver">
<span id="s-staticfiles-runserver"></span><span id="runserver"></span><span id="staticfiles-runserver"></span><h3><code class="docutils literal notranslate"><span class="pre">runserver</span></code><a class="headerlink" href="#runserver" title="Permalink to this headline">¶</a></h3>
<dl class="django-admin">
<dt id="django-admin-runserver">
<code class="descname">django-admin runserver [addrport]</code><a class="headerlink" href="#django-admin-runserver" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Overrides the core <a class="reference internal" href="../django-admin.html#django-admin-runserver"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">runserver</span></code></a> command if the <code class="docutils literal notranslate"><span class="pre">staticfiles</span></code> app
is <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">installed</span></code></a> and adds automatic serving of static
files. File serving doesn’t run through <a class="reference internal" href="../settings.html#std:setting-MIDDLEWARE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MIDDLEWARE</span></code></a>.</p>
<p>The command adds these options:</p>
<dl class="django-admin-option">
<dt id="cmdoption-runserver-nostatic">
<code class="descname">--nostatic</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-runserver-nostatic" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Use the <code class="docutils literal notranslate"><span class="pre">--nostatic</span></code> option to disable serving of static files with the
<a class="reference internal" href="#"><span class="doc">staticfiles</span></a> app entirely. This option is
only available if the <a class="reference internal" href="#"><span class="doc">staticfiles</span></a> app is
in your project’s <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a> setting.</p>
<p>Example usage:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">django-admin runserver --nostatic</span>
</pre></div>
</div>
<dl class="django-admin-option">
<dt id="cmdoption-runserver-insecure">
<code class="descname">--insecure</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-runserver-insecure" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Use the <code class="docutils literal notranslate"><span class="pre">--insecure</span></code> option to force serving of static files with the
<a class="reference internal" href="#"><span class="doc">staticfiles</span></a> app even if the <a class="reference internal" href="../settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a>
setting is <code class="docutils literal notranslate"><span class="pre">False</span></code>. By using this you acknowledge the fact that it’s
<strong>grossly inefficient</strong> and probably <strong>insecure</strong>. This is only intended for
local development, should <strong>never be used in production</strong> and is only
available if the <a class="reference internal" href="#"><span class="doc">staticfiles</span></a> app is
in your project’s <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a> setting. <a class="reference internal" href="../django-admin.html#django-admin-runserver"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">runserver</span></code></a>
<code class="docutils literal notranslate"><span class="pre">--insecure</span></code> doesn’t work with
<a class="reference internal" href="#django.contrib.staticfiles.storage.CachedStaticFilesStorage" title="django.contrib.staticfiles.storage.CachedStaticFilesStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">CachedStaticFilesStorage</span></code></a>.</p>
<p>Example usage:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">django-admin runserver --insecure</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-storages">
<span id="s-staticfiles-storages"></span><span id="storages"></span><span id="staticfiles-storages"></span><h2>Storages<a class="headerlink" href="#storages" title="Permalink to this headline">¶</a></h2>
<div class="section" id="s-staticfilesstorage">
<span id="staticfilesstorage"></span><h3><code class="docutils literal notranslate"><span class="pre">StaticFilesStorage</span></code><a class="headerlink" href="#staticfilesstorage" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.contrib.staticfiles.storage.StaticFilesStorage">
<em class="property">class </em><code class="descclassname">storage.</code><code class="descname">StaticFilesStorage</code><a class="headerlink" href="#django.contrib.staticfiles.storage.StaticFilesStorage" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>A subclass of the <a class="reference internal" href="../files/storage.html#django.core.files.storage.FileSystemStorage" title="django.core.files.storage.FileSystemStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileSystemStorage</span></code></a>
storage backend that uses the <a class="reference internal" href="../settings.html#std:setting-STATIC_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code></a> setting as the base
file system location and the <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> setting respectively
as the base URL.</p>
<dl class="method">
<dt id="django.contrib.staticfiles.storage.StaticFilesStorage.post_process">
<code class="descclassname">storage.StaticFilesStorage.</code><code class="descname">post_process</code>(<em>paths</em>, <em>**options</em>)<a class="headerlink" href="#django.contrib.staticfiles.storage.StaticFilesStorage.post_process" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>This method is called by the <a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> management command
after each run and gets passed the local storages and paths of found
files as a dictionary, as well as the command line options.</p>
<p>The <a class="reference internal" href="#django.contrib.staticfiles.storage.CachedStaticFilesStorage" title="django.contrib.staticfiles.storage.CachedStaticFilesStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">CachedStaticFilesStorage</span></code></a>
uses this behind the scenes to replace the paths with their hashed
counterparts and update the cache appropriately.</p>
</div>
<div class="section" id="s-manifeststaticfilesstorage">
<span id="manifeststaticfilesstorage"></span><h3><code class="docutils literal notranslate"><span class="pre">ManifestStaticFilesStorage</span></code><a class="headerlink" href="#manifeststaticfilesstorage" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.contrib.staticfiles.storage.ManifestStaticFilesStorage">
<em class="property">class </em><code class="descclassname">storage.</code><code class="descname">ManifestStaticFilesStorage</code><a class="headerlink" href="#django.contrib.staticfiles.storage.ManifestStaticFilesStorage" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>A subclass of the <a class="reference internal" href="#django.contrib.staticfiles.storage.StaticFilesStorage" title="django.contrib.staticfiles.storage.StaticFilesStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">StaticFilesStorage</span></code></a>
storage backend which stores the file names it handles by appending the MD5
hash of the file’s content to the filename. For example, the file
<code class="docutils literal notranslate"><span class="pre">css/styles.css</span></code> would also be saved as <code class="docutils literal notranslate"><span class="pre">css/styles.55e7cbb9ba48.css</span></code>.</p>
<p>The purpose of this storage is to keep serving the old files in case some
pages still refer to those files, e.g. because they are cached by you or
a 3rd party proxy server. Additionally, it’s very helpful if you want to
apply <a class="reference external" href="https://developer.yahoo.com/performance/rules.html#expires">far future Expires headers</a> to the deployed files to speed up the
load time for subsequent page visits.</p>
<p>The storage backend automatically replaces the paths found in the saved
files matching other saved files with the path of the cached copy (using
the <a class="reference internal" href="#django.contrib.staticfiles.storage.StaticFilesStorage.post_process" title="django.contrib.staticfiles.storage.StaticFilesStorage.post_process"><code class="xref py py-meth docutils literal notranslate"><span class="pre">post_process()</span></code></a>
method). The regular expressions used to find those paths
(<code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles.storage.HashedFilesMixin.patterns</span></code>)
by default covers the <a class="reference external" href="http://www.w3.org/TR/CSS2/cascade.html#at-import">&#64;import</a> rule and <a class="reference external" href="http://www.w3.org/TR/CSS2/syndata.html#uri">url()</a> statement of <a class="reference external" href="http://www.w3.org/Style/CSS/">Cascading
Style Sheets</a>. For example, the <code class="docutils literal notranslate"><span class="pre">'css/styles.css'</span></code> file with the
content</p>
<div class="highlight-css+django notranslate"><div class="highlight"><pre><span></span><span class="p">@</span><span class="k">import</span> <span class="nt">url</span><span class="o">(</span><span class="s2">&quot;../admin/css/base.css&quot;</span><span class="o">)</span><span class="p">;</span>
</pre></div>
</div>
<p>would be replaced by calling the <a class="reference internal" href="../files/storage.html#django.core.files.storage.Storage.url" title="django.core.files.storage.Storage.url"><code class="xref py py-meth docutils literal notranslate"><span class="pre">url()</span></code></a>
method of the <code class="docutils literal notranslate"><span class="pre">ManifestStaticFilesStorage</span></code> storage backend, ultimately
saving a <code class="docutils literal notranslate"><span class="pre">'css/styles.55e7cbb9ba48.css'</span></code> file with the following
content:</p>
<div class="highlight-css+django notranslate"><div class="highlight"><pre><span></span><span class="p">@</span><span class="k">import</span> <span class="nt">url</span><span class="o">(</span><span class="s2">&quot;../admin/css/base.27e20196a850.css&quot;</span><span class="o">)</span><span class="p">;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.staticfiles.storage.ManifestStaticFilesStorage.max_post_process_passes">
<code class="descclassname">storage.ManifestStaticFilesStorage.</code><code class="descname">max_post_process_passes</code><a class="headerlink" href="#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.max_post_process_passes" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Since static files might reference other static files that need to have their
paths replaced, multiple passes of replacing paths may be needed until the file
hashes converge. To prevent an infinite loop due to hashes not converging (for
example, if <code class="docutils literal notranslate"><span class="pre">'foo.css'</span></code> references <code class="docutils literal notranslate"><span class="pre">'bar.css'</span></code> which references
<code class="docutils literal notranslate"><span class="pre">'foo.css'</span></code>) there is a maximum number of passes before post-processing is
abandoned. In cases with a large number of references, a higher number of
passes might be needed. Increase the maximum number of passes by subclassing
<code class="docutils literal notranslate"><span class="pre">ManifestStaticFilesStorage</span></code> and setting the <code class="docutils literal notranslate"><span class="pre">max_post_process_passes</span></code>
attribute. It defaults to 5.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.11:</span> <p>Previous versions didn’t make multiple passes to ensure file hashes
converged, so often times file hashes weren’t correct. The
<code class="docutils literal notranslate"><span class="pre">max_post_process_passes</span></code> attribute was added.</p>
</div>
<p>To enable the <code class="docutils literal notranslate"><span class="pre">ManifestStaticFilesStorage</span></code> you have to make sure the
following requirements are met:</p>
<ul class="simple">
<li>the <a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_STORAGE</span></code></a> setting is set to
<code class="docutils literal notranslate"><span class="pre">'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'</span></code></li>
<li>the <a class="reference internal" href="../settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a> setting is set to <code class="docutils literal notranslate"><span class="pre">False</span></code></li>
<li>you’ve collected all your static files by using the
<a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> management command</li>
</ul>
<div class="versionchanged">
<span class="title">Changed in Django 1.10:</span> <p>In older versions, you also had to use
<code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">static</span> <span class="pre">from</span> <span class="pre">staticfiles</span> <span class="pre">%}</span></code> in your template. The
<a class="reference internal" href="../templates/builtins.html#std:templatetag-static"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">static</span></code></a> template tag (<code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">static</span> <span class="pre">%}</span></code>) now uses
<a class="reference internal" href="#module-django.contrib.staticfiles" title="django.contrib.staticfiles: An app for handling static files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.staticfiles</span></code></a> if it’s installed.</p>
</div>
<p>Since creating the MD5 hash can be a performance burden to your website
during runtime, <code class="docutils literal notranslate"><span class="pre">staticfiles</span></code> will automatically store the mapping with
hashed names for all processed files in a file called <code class="docutils literal notranslate"><span class="pre">staticfiles.json</span></code>.
This happens once when you run the <a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> management
command.</p>
<dl class="attribute">
<dt id="django.contrib.staticfiles.storage.ManifestStaticFilesStorage.manifest_strict">
<code class="descclassname">storage.ManifestStaticFilesStorage.</code><code class="descname">manifest_strict</code><a class="headerlink" href="#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.manifest_strict" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>If a file isn’t found in the <code class="docutils literal notranslate"><span class="pre">staticfiles.json</span></code> manifest at runtime, a
<code class="docutils literal notranslate"><span class="pre">ValueError</span></code> is raised. This behavior can be disabled by subclassing
<code class="docutils literal notranslate"><span class="pre">ManifestStaticFilesStorage</span></code> and setting the <code class="docutils literal notranslate"><span class="pre">manifest_strict</span></code> attribute to
<code class="docutils literal notranslate"><span class="pre">False</span></code> – nonexistent paths will remain unchanged.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.11:</span> <p>The <code class="docutils literal notranslate"><span class="pre">manifest_strict</span></code> attribute was added. In older versions, the
behavior is the same as <code class="docutils literal notranslate"><span class="pre">manifest_strict=False</span></code>.</p>
</div>
<p>Due to the requirement of running <a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a>, this storage
typically shouldn’t be used when running tests as <code class="docutils literal notranslate"><span class="pre">collectstatic</span></code> isn’t run
as part of the normal test setup. During testing, ensure that the
<a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_STORAGE</span></code></a> setting is set to something else like
<code class="docutils literal notranslate"><span class="pre">'django.contrib.staticfiles.storage.StaticFilesStorage'</span></code> (the default).</p>
<dl class="method">
<dt id="django.contrib.staticfiles.storage.ManifestStaticFilesStorage.file_hash">
<code class="descclassname">storage.ManifestStaticFilesStorage.</code><code class="descname">file_hash</code>(<em>name</em>, <em>content=None</em>)<a class="headerlink" href="#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.file_hash" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The method that is used when creating the hashed name of a file.
Needs to return a hash for the given file name and content.
By default it calculates a MD5 hash from the content’s chunks as
mentioned above. Feel free to override this method to use your own
hashing algorithm.</p>
</div>
<div class="section" id="s-cachedstaticfilesstorage">
<span id="cachedstaticfilesstorage"></span><h3><code class="docutils literal notranslate"><span class="pre">CachedStaticFilesStorage</span></code><a class="headerlink" href="#cachedstaticfilesstorage" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.contrib.staticfiles.storage.CachedStaticFilesStorage">
<em class="property">class </em><code class="descclassname">storage.</code><code class="descname">CachedStaticFilesStorage</code><a class="headerlink" href="#django.contrib.staticfiles.storage.CachedStaticFilesStorage" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p><code class="docutils literal notranslate"><span class="pre">CachedStaticFilesStorage</span></code> is a similar class like the
<a class="reference internal" href="#django.contrib.staticfiles.storage.ManifestStaticFilesStorage" title="django.contrib.staticfiles.storage.ManifestStaticFilesStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">ManifestStaticFilesStorage</span></code></a> class
but uses Django’s <a class="reference internal" href="../../topics/cache.html"><span class="doc">caching framework</span></a> for storing the
hashed names of processed files instead of a static manifest file called
<code class="docutils literal notranslate"><span class="pre">staticfiles.json</span></code>. This is mostly useful for situations in which you don’t
have access to the file system.</p>
<p>If you want to override certain options of the cache backend the storage uses,
simply specify a custom entry in the <a class="reference internal" href="../settings.html#std:setting-CACHES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CACHES</span></code></a> setting named
<code class="docutils literal notranslate"><span class="pre">'staticfiles'</span></code>. It falls back to using the <code class="docutils literal notranslate"><span class="pre">'default'</span></code> cache backend.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last"><code class="docutils literal notranslate"><span class="pre">CachedStaticFilesStorage</span></code> isn’t recommended –  in almost all cases
<code class="docutils literal notranslate"><span class="pre">ManifestStaticFilesStorage</span></code> is a better choice. There are several
performance penalties when using <code class="docutils literal notranslate"><span class="pre">CachedStaticFilesStorage</span></code> since a cache
miss requires hashing files at runtime. Remote file storage require several
round-trips to hash a file on a cache miss, as several file accesses are
required to ensure that the file hash is correct in the case of nested file
paths.</p>
</div>
</div>
</div>
<div class="section" id="s-finders-module">
<span id="finders-module"></span><h2>Finders Module<a class="headerlink" href="#finders-module" title="Permalink to this headline">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">staticfiles</span></code> finders has a <code class="docutils literal notranslate"><span class="pre">searched_locations</span></code> attribute which is a list
of directory paths in which the finders searched. Example usage:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">from django.contrib.staticfiles import finders</span>

<span class="go">result = finders.find(&#39;css/base.css&#39;)</span>
<span class="go">searched_locations = finders.searched_locations</span>
</pre></div>
</div>
</div>
<div class="section" id="s-other-helpers">
<span id="other-helpers"></span><h2>Other Helpers<a class="headerlink" href="#other-helpers" title="Permalink to this headline">¶</a></h2>
<p>There are a few other helpers outside of the
<a class="reference internal" href="#module-django.contrib.staticfiles" title="django.contrib.staticfiles: An app for handling static files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">staticfiles</span></code></a> app to work with static
files:</p>
<ul class="simple">
<li>The <a class="reference internal" href="../templates/api.html#django.template.context_processors.static" title="django.template.context_processors.static"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.template.context_processors.static()</span></code></a> context processor
which adds <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> to every template context rendered
with <a class="reference internal" href="../templates/api.html#django.template.RequestContext" title="django.template.RequestContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">RequestContext</span></code></a> contexts.</li>
<li>The builtin template tag <a class="reference internal" href="../templates/builtins.html#std:templatetag-static"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">static</span></code></a> which takes a path and urljoins it
with the static prefix <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a>. If
<code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles</span></code> is installed, the tag uses the <code class="docutils literal notranslate"><span class="pre">url()</span></code>
method of the <a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_STORAGE</span></code></a> instead.</li>
<li>The builtin template tag <a class="reference internal" href="../templates/builtins.html#std:templatetag-get_static_prefix"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">get_static_prefix</span></code></a> which populates a
template variable with the static prefix <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> to be
used as a variable or directly.</li>
<li>The similar template tag <a class="reference internal" href="../templates/builtins.html#std:templatetag-get_media_prefix"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">get_media_prefix</span></code></a> which works like
<a class="reference internal" href="../templates/builtins.html#std:templatetag-get_static_prefix"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">get_static_prefix</span></code></a> but uses <a class="reference internal" href="../settings.html#std:setting-MEDIA_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_URL</span></code></a>.</li>
</ul>
<div class="section" id="s-static-file-development-view">
<span id="s-staticfiles-development-view"></span><span id="static-file-development-view"></span><span id="staticfiles-development-view"></span><h3>Static file development view<a class="headerlink" href="#static-file-development-view" title="Permalink to this headline">¶</a></h3>
<p>The static files tools are mostly designed to help with getting static files
successfully deployed into production. This usually means a separate,
dedicated static file server, which is a lot of overhead to mess with when
developing locally. Thus, the <code class="docutils literal notranslate"><span class="pre">staticfiles</span></code> app ships with a
<strong>quick and dirty helper view</strong> that you can use to serve files locally in
development.</p>
<dl class="function">
<dt id="django.contrib.staticfiles.views.serve">
<code class="descclassname">views.</code><code class="descname">serve</code>(<em>request</em>, <em>path</em>)<a class="headerlink" href="#django.contrib.staticfiles.views.serve" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>This view function serves static files in development.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>This view will only work if <a class="reference internal" href="../settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a> is <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
<p class="last">That’s because this view is <strong>grossly inefficient</strong> and probably
<strong>insecure</strong>. This is only intended for local development, and should
<strong>never be used in production</strong>.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">To guess the served files’ content types, this view relies on the
<a class="reference external" href="https://docs.python.org/3/library/mimetypes.html#module-mimetypes" title="(in Python v3.7)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mimetypes</span></code></a> module from the Python standard library, which itself
relies on the underlying platform’s map files. If you find that this view
doesn’t return proper content types for certain files, it is most likely
that the platform’s map files need to be updated. This can be achieved, for
example, by installing or updating the <code class="docutils literal notranslate"><span class="pre">mailcap</span></code> package on a Red Hat
distribution, or <code class="docutils literal notranslate"><span class="pre">mime-support</span></code> on a Debian distribution.</p>
</div>
<p>This view is automatically enabled by <a class="reference internal" href="../django-admin.html#django-admin-runserver"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">runserver</span></code></a> (with a
<a class="reference internal" href="../settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a> setting set to <code class="docutils literal notranslate"><span class="pre">True</span></code>). To use the view with a different
local development server, add the following snippet to the end of your
primary URL configuration:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf</span> <span class="kn">import</span> <span class="n">settings</span>
<span class="kn">from</span> <span class="nn">django.contrib.staticfiles</span> <span class="kn">import</span> <span class="n">views</span>

<span class="k">if</span> <span class="n">settings</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">:</span>
    <span class="n">urlpatterns</span> <span class="o">+=</span> <span class="p">[</span>
        <span class="n">url</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^static/(?P&lt;path&gt;.*)$&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">serve</span><span class="p">),</span>
    <span class="p">]</span>
</pre></div>
</div>
<p>Note, the beginning of the pattern (<code class="docutils literal notranslate"><span class="pre">r'^static/'</span></code>) should be your
<a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> setting.</p>
<p>Since this is a bit finicky, there’s also a helper function that’ll do this for
you:</p>
<dl class="function">
<dt id="django.contrib.staticfiles.urls.staticfiles_urlpatterns">
<code class="descclassname">urls.</code><code class="descname">staticfiles_urlpatterns</code>()<a class="headerlink" href="#django.contrib.staticfiles.urls.staticfiles_urlpatterns" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>This will return the proper URL pattern for serving static files to your
already defined pattern list. Use it like this:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.contrib.staticfiles.urls</span> <span class="kn">import</span> <span class="n">staticfiles_urlpatterns</span>

<span class="c1"># ... the rest of your URLconf here ...</span>

<span class="n">urlpatterns</span> <span class="o">+=</span> <span class="n">staticfiles_urlpatterns</span><span class="p">()</span>
</pre></div>
</div>
<p>This will inspect your <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> setting and wire up the view
to serve static files accordingly. Don’t forget to set the
<a class="reference internal" href="../settings.html#std:setting-STATICFILES_DIRS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_DIRS</span></code></a> setting appropriately to let
<code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles</span></code> know where to look for files in addition to
files in app directories.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>This helper function will only work if <a class="reference internal" href="../settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a> is <code class="docutils literal notranslate"><span class="pre">True</span></code>
and your <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> setting is neither empty nor a full
URL such as <code class="docutils literal notranslate"><span class="pre">http://static.example.com/</span></code>.</p>
<p class="last">That’s because this view is <strong>grossly inefficient</strong> and probably
<strong>insecure</strong>. This is only intended for local development, and should
<strong>never be used in production</strong>.</p>
</div>
</div>
<div class="section" id="s-specialized-test-case-to-support-live-testing">
<span id="specialized-test-case-to-support-live-testing"></span><h3>Specialized test case to support ‘live testing’<a class="headerlink" href="#specialized-test-case-to-support-live-testing" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.contrib.staticfiles.testing.StaticLiveServerTestCase">
<em class="property">class </em><code class="descclassname">testing.</code><code class="descname">StaticLiveServerTestCase</code><a class="headerlink" href="#django.contrib.staticfiles.testing.StaticLiveServerTestCase" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>This unittest TestCase subclass extends <a class="reference internal" href="../../topics/testing/tools.html#django.test.LiveServerTestCase" title="django.test.LiveServerTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.test.LiveServerTestCase</span></code></a>.</p>
<p>Just like its parent, you can use it to write tests that involve running the
code under test and consuming it with testing tools through HTTP (e.g. Selenium,
PhantomJS, etc.), because of which it’s needed that the static assets are also
published.</p>
<p>But given the fact that it makes use of the
<a class="reference internal" href="#django.contrib.staticfiles.views.serve" title="django.contrib.staticfiles.views.serve"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.contrib.staticfiles.views.serve()</span></code></a> view described above, it can
transparently overlay at test execution-time the assets provided by the
<code class="docutils literal notranslate"><span class="pre">staticfiles</span></code> finders. This means you don’t need to run
<a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> before or as a part of your tests setup.</p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">The <code class="docutils literal notranslate"><span class="pre">staticfiles</span></code> app</a><ul>
<li><a class="reference internal" href="#settings">Settings</a></li>
<li><a class="reference internal" href="#management-commands">Management Commands</a><ul>
<li><a class="reference internal" href="#collectstatic"><code class="docutils literal notranslate"><span class="pre">collectstatic</span></code></a><ul>
<li><a class="reference internal" href="#customizing-the-ignored-pattern-list">Customizing the ignored pattern list</a></li>
</ul>
</li>
<li><a class="reference internal" href="#findstatic"><code class="docutils literal notranslate"><span class="pre">findstatic</span></code></a></li>
<li><a class="reference internal" href="#runserver"><code class="docutils literal notranslate"><span class="pre">runserver</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#storages">Storages</a><ul>
<li><a class="reference internal" href="#staticfilesstorage"><code class="docutils literal notranslate"><span class="pre">StaticFilesStorage</span></code></a></li>
<li><a class="reference internal" href="#manifeststaticfilesstorage"><code class="docutils literal notranslate"><span class="pre">ManifestStaticFilesStorage</span></code></a></li>
<li><a class="reference internal" href="#cachedstaticfilesstorage"><code class="docutils literal notranslate"><span class="pre">CachedStaticFilesStorage</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#finders-module">Finders Module</a></li>
<li><a class="reference internal" href="#other-helpers">Other Helpers</a><ul>
<li><a class="reference internal" href="#static-file-development-view">Static file development view</a></li>
<li><a class="reference internal" href="#specialized-test-case-to-support-live-testing">Specialized test case to support ‘live testing’</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="sites.html"
                        title="previous chapter">The “sites” framework</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="syndication.html"
                        title="next chapter">The syndication feed framework</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/ref/contrib/staticfiles.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Jun 03, 2019</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="sites.html" title="The “sites” framework">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="syndication.html" title="The syndication feed framework">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>